#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
    ll n, m;
    ll x, y;
    cin >> n >> m;
    cin >> x >> y;
    vector<ll> a(n),b(m);
    map<int,int> mpa,mpb;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        mpa[a[i]]++;
    }
    ll ans = 0;
    for (ll i = 0; i < m; i++)
    {
        cin >> b[i];
        if(mpa[b[i]]>0)
        {
            mpb[b[i]]++;
        }
    }
    cout << n + m << endl;
}
int main()
{
    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}